package Exercise;

import java.util.concurrent.locks.ReentrantLock;

public class windowTest4 {
    public static void main(String[] args) {
        window4 t1 = new window4();
        window4 t2 = new window4();
        window4 t3 = new window4();
        t1.setName("窗口一");
        t2.setName("窗口二");
        t3.setName("窗口三");

        t1.start();
        t2.start();
        t3.start();
    }
}


class window4 extends Thread {
    private static int TICKTE = 100;
    private static ReentrantLock lock = new ReentrantLock();

    public void run() {

        while (true) {
            try {
                lock.lock();
                if (TICKTE > 0) {
                    System.out.println(Thread.currentThread().getName() + ":卖票,票号为:" + TICKTE);
                    TICKTE--;
                } else {
                    break;
                }
            }finally {
                lock.unlock();
            }
        }
    }

}